﻿using Avin.Infrastructure;
using System;
using System.Linq;
using Tester.Entity;
using Tester.Result;

namespace Tester
{
    class Program
    {
        static Repository<Art2> artRepository = new();
        static Repository<ArtCategory2> artCategoryRepository = new();
        static Repository<User2> userRepository = new();

        static void Main(string[] args)
        {
            ParamTest param = new()
            {
                Int = 8,
                String = "Test"
            };
            Test(param);
        }

        static void Test(ParamTest param)
        {
            //Console.WriteLine("------------------------------------单表测试，先where再select------------------------------------");
            //var queryable1 = artRepository.Queryable;
            //queryable1.Where(a => !a.IsDeleted);
            //queryable1.Where(a => a.Title.IndexOf(param.String) >= 0);
            //queryable1.Take(param.Int);

            //queryable1.OrderBy(a => a.CategoryId);

            //Console.WriteLine(queryable1.Count());
            //Console.WriteLine(queryable1.ToList().ToJson());
            //Console.WriteLine();

            //Console.WriteLine("------------------------------------单表测试，先select再where------------------------------------");
            //var queryable2 = queryable1.Select(a => new Result1
            //{
            //    Title = a.Title,
            //    CategoryId = a.CategoryId,
            //    Good = a.SongFeiJi + a.SongHua + param.Int
            //});
            //queryable2.Where(a => a.Good > param.Int);

            //queryable2.Take(param.Int);
            //queryable2.OrderByDescending(a => a.CategoryId);

            //Console.WriteLine(queryable2.Count());
            //Console.WriteLine(queryable2.ToList().ToJson());


            var queryable3 = from a in artRepository.Queryable
                             join b in artCategoryRepository.Queryable on a.CategoryId equals b.Id
                             where a.Title == null
                             group new { a, b } by new { b.Title, b.Id }
                             into g
                             select new Result2
                             {
                                 Id = g.Key.Id,
                                 Title = g.Key.Title,
                                 Count = g.Count()
                             };
            var data3 = queryable3.ToList();
            Console.WriteLine(data3.ToJson());
        }
    }

    public class ParamTest
    {
        public int Int { get; set; }

        public string String { get; set; }
    }
}
